<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <script src="https://cdn.bootcss.com/jquery/2.1.2/jquery.min.js"></script>
    <script>

        $(function(){

            $("#subBtn").click(function () {

                //初始化报错信息
                $("#err_opwd").html('');
                $("#err_npwd").html('');
                $("#err_npwds").html('');

                //执行当前表单的数据验证
                var opwd, npwd, npwds, flag = true;
                opwd = $("#opwd").val();
                npwd = $("#npwd").val();
                npwds = $("#npwds").val();

                if (opwd == "") {
                    $("#err_opwd").html("提示：原始密码不能为空！");
                    flag = false;
                }
                if (npwd == "") {
                    $("#err_npwd").html("提示：原始密码不能为空！");
                    flag = false;
                }
                if (npwds == "") {
                    $("#err_npwds").html("提示：原始密码不能为空！");
                    flag = false;
                }
                //验证新密码 与 确认密码是否相同
                if (npwd != npwds) {
                    $("#err_npwds").html("提示：确认密码不一致！");
                    flag = false;
                }

                if (flag) {
                    //进行提交数据 AJAX

                    $.post('public/ajax/changPwd.php', {opwd:opwd, npwd:npwd, npwds:npwds}, function (data) {
                        if (data.code == 200) {
                            alert('提示：登陆密码已修改成功');
                            window.location.href = 'list.php';
                            return;
                        } else if(data.code == 501) {
                            $("#err_npwds").html("提示：确认密码不一致！");
                            return;
                        } else if(data.code == 502) {
                            $("#err_opwd").html("提示：原始密码错误！");
                            return;
                        } else if(data.code == 503) {
                            alert('提示：密码修改失败');
                            return;
                        }
                    }, 'json');

                }

            });

        });

    </script>
    <style>
        .error{
            font-size: 12px;
            color: red;
        }
    </style>
    <title>修改密码</title>
    <meta name="keywords" content="个人博客" />
    <meta name="description" content="" />
    <link rel="stylesheet" href="css/index.css"/>
    <link rel="stylesheet" href="css/style.css"/>
    <script type="text/javascript" src="js/jquery1.42.min.js"></script>
    <script type="text/javascript" src="js/jquery.SuperSlide.2.1.1.js"></script>
    <!--[if lt IE 9]>
    <script src="js/html5.js"></script>
    <![endif]-->
</head>
<body>

<!--nav-->
<div id="nav">
    <ul>
        <li><a href="list.php">文章列表</a></li>
        <li><a href="add_blog.php">发布文章</a></li>
        <li><a href="changePwd.php">修改密码</a></li>
        <div class="clear"></div>
    </ul>
</div>
<!--nav end-->
<!--content start-->
<div id="content">
    <!--left-->
    <div class="left" id="guestbook">
        <div class="weizi">
            <div class="wz_text">当前位置：<a href="#">首页</a>><h1>修改密码</h1></div>
        </div>
        <div class="g_content">
            <?php

            //连接数据库
            include 'inc/conn.php';

            //验证用户登陆
            include 'inc/checkSesion.php';


            ?>


            <div>




                <form>



                    <p>
                        原密码：<input type="password" name="opwd" id="opwd">
                        <label id="err_opwd" class="error"></label>
                    </p>
       </br>
                    <p>
                        新密码：<input type="password" name="npwd" id="npwd">
                        <label id="err_npwd" class="error"></label>
                    </p>
                    </br>
                    <p>
                        确认密码：<input type="password" name="npwds" id="npwds">
                        <label id="err_npwds" class="error"></label>
                    </p>
                    </br>
                    <button type="button" id="subBtn">确认修改</button>



                </form>


            </div>
        </div>
    </div>
    <!--end left -->
    <!--right-->


<!--footer end-->
<script type="text/javascript">jQuery(".lanmubox").slide({easing:"easeOutBounce",delayTime:400});</script>
<script  type="text/javascript" src="js/nav.js"></script>


</body>
</html>